<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>lai</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="layuiadmin/layui/css/layui.css" media="all">
</head>
<body>
<div id="editForm" style="display: none">
    <ins class="adsbygoogle"
         style="display: inline-block; width: 300px; height: 15px"
         data-ad-client="ca-pub-6111334333458862" data-ad-slot="3820120620"></ins>


    <form class="layui-form" action="" lay-filter="example">


        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">ID</label>
                <div class="layui-input-inline">
                    <input type="tel" name="mid" id="mid" readonly="readonly" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">电影名</label>
                <div class="layui-input-inline">
                    <input type="tel" name="mname" id="mname" readonly="readonly" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>

        <div class="layui-form-item" style="display:none">
            <label class="layui-form-label">图片</label>
            <div class="layui-input-block">
                <input type="text" name="mpicture" id="mpicture"
                       lay-verify="title" autocomplete="off" placeholder=""
                       class="layui-input">
            </div>
        </div>


        <div class="layui-form-item" style="display:none">
            <label class="layui-form-label">导演</label>
            <div class="layui-input-block">
                <input type="text" name="mdirector" id="mdirector" lay-verify="title"
                       autocomplete="off" placeholder="" class="layui-input" readonly="readonly">
            </div>
        </div>
        <div class="layui-form-item" style="display:none">
            <label class="layui-form-label">演员</label>
            <div class="layui-input-block">
                <input type="text" name="mactor" id="mactor" lay-verify="title"
                       autocomplete="off" placeholder="" class="layui-input" readonly="readonly">
            </div>
        </div>

        <div class="layui-form-item" style="display:none">
            <label class="layui-form-label">类型</label>
            <div class="layui-input-block">
                <input type="text" name="mtype" id="mtype" lay-verify="title"
                       autocomplete="off" placeholder="" class="layui-input" readonly="readonly">
            </div>
        </div>

        <div class="layui-form-item" style="display:none">
            <label class="layui-form-label">地区</label>
            <div class="layui-input-block">
                <input type="text" name="mcountry" id="mcountry" lay-verify="title"
                       autocomplete="off" placeholder="" class="layui-input" readonly="readonly">
            </div>
        </div>


        <div class="layui-form-item" style="display: none">
            <label class="layui-form-label">语言</label>
            <div class="layui-input-block">
                <input type="text" name="mlanguage" id="mlanguage" lay-verify="title"
                       autocomplete="off" placeholder="" class="layui-input" readonly="readonly">
            </div>
        </div>

        <div class="layui-form-item" style="display:none">
            <label class="layui-form-label">电影时长</label>
            <div class="layui-input-block">
                <input type="text" name="mplaytime" id="mplaytime" lay-verify="title"
                       autocomplete="off" placeholder="" class="layui-input" readonly="readonly">
            </div>
        </div>

        <div class="layui-form-item" style="display:none">
            <label class="layui-form-label">电影评分</label>
            <div class="layui-input-block">
                <input type="text" name="mgrade" id="mgrade" lay-verify="title"
                       autocomplete="off" placeholder="" class="layui-input" readonly="readonly">
            </div>
        </div>
        <div class="layui-form-item" style="display:none">
            <label class="layui-form-label">选座购票</label>
            <div class="layui-input-block">
                <input type="text" name="mreleasedtime" id="mreleasedtime" lay-verify="title"
                       autocomplete="off" placeholder="" class="layui-input" readonly="readonly">
            </div>
        </div>

        <div class="layui-form-item" style="display:none">
            <label class="layui-form-label">预告片</label>
            <div class="layui-input-block">
                <input type="text" name="mvideo" id="mvideo" lay-verify="title"
                       autocomplete="off" placeholder="" class="layui-input" readonly="readonly">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <input type="radio" name="mstatus" value="1"
                       title="热映" checked="">
                <input type="radio" name="mstatus" value="2" title="预售">

            </div>
        </div>


        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
            </div>
        </div>
    </form>
</div>


<div class="demoTable">
    搜索名字：
    <div class="layui-inline">
        <input class="layui-input" name="id" id="demoReload"
               autocomplete="off">
    </div>
    <button class="layui-btn" data-type="reload">搜索</button>
</div>

<table class="layui-hide" id="test" lay-filter="test"></table>

<script type="text/html" id="toolbarDemo">
   <%-- <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
        <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>
        <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>
    </div>--%>
</script>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <%--<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>--%>
</script>

<script src="layuiadmin/layui/layui.js"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.use('table', function my() {
        var table = layui.table;

        table.render({
            elem: '#test',
            url: 'movieList',
            toolbar: '#toolbarDemo',
            height: 550,
            title: '电影数据表',
            cols: [[{
                type: 'checkbox',
                fixed: 'left'
            }, /*{
                field: 'mid',
                title: 'ID',

                fixed: 'left',
                unresize: true,
                sort: true
            },*/ {
                field: 'mname',
                title: '电影名',


            }, {
                field: 'mpicture',
                title: '图片',
               /* style:'height:100px;',*/
                /*templet: '#mpicture',*/
                templet: function (res) {
                    return "<div><img src='" + res.mpicture + "'></div>"
                }

            }, {
                field: 'mdirector',
                title: '导演',


            }, {
                field: 'mactor',
                title: '演员',


            }, {
                field: 'mplaytime',
                title: '时长',


            }, /*{
             field : 'mreleasedtime',
             title : '选座购票',
             width : 120,
             }*/{
                field: 'mstatus',
                title: '状态',


                templet: function (res) {
                    var name;
                    if (res.mstatus == 1) {
                        name = "热映"
                    }
                    if (res.mstatus == 2) {
                        name = "预售"
                    }

                    return name
                }
            }, {
                field: 'mvideo',
                title: '电影预告',


            }, {
                field: 'mgrade',
                title: '电影评分',

            }, {
                fixed: 'right',
                title: '操作',
                toolbar: '#barDemo',

            }]],
            page: true,
            id: 'testReload'
        });

        //头工具栏事件
        table.on('toolbar(test)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'getCheckData':
                    var data = checkStatus.data;
                    layer.alert(JSON.stringify(data));
                    break;
                case 'getCheckLength':
                    var data = checkStatus.data;
                    layer.msg('选中了：' + data.length + ' 个');
                    break;
                case 'isAll':
                    layer.msg(checkStatus.isAll ? '全选' : '未全选');
                    break;

            }
            ;
        });
        //监听行工具事件
        table.on('tool(test)', function (obj) {
            var data = obj.data;
            if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){
                    $.ajax({
                        'type' : 'delete',
                        'url' : 'deleteMovie/' + data.mid,
                        'success' : function(cm) {
                            layer.msg(cm.msg, {
                                time : 1500
                            }, function() {
                                if (cm.msg == "删除成功") {
                                    layer.closeAll();
                                    table.reload('testReload');//重新加载列表
                                }
                            })
                        }
                    });

                   /* obj.del();
                    layer.close(index);*/
                });
            }

            else if (obj.event === 'edit') {
                $("#mid").attr("value", data.mid);
                $("#mname").attr("value", data.mname);
                $("#mpicture").attr("value", data.mpicture);
                $("#mdirector").attr("value", data.mdirector);
                $("#mactor").attr("value", data.mactor);
                $("#mtype").attr("value", data.mtype);
                $("#mcountry").attr("value", data.mcountry);
                $("#mlanguage").attr("value", data.mlanguage);
                $("#mplaytime").attr("value", data.mplaytime);
                $("#mreleasedtime").attr("value", data.mreleasedtime);
                $("#mvideo").attr("value", data.mvideo);
                $("#mgrade").attr("value", data.mgrade);
                $("input[name='mstatus'][value=1]").attr("checked",
                    data.mstatus == 1 ? true : false);
                $("input[name='mstatus'][value=2]").attr("checked",
                    data.mstatus == 2 ? true : false);
                var index1 = layer.open({
                    type: 1,
                    content: $("#editForm").html(),
                });
                //只有加了这一句，表单的复选框，单选框才可以编辑
                layui.form.render();
                //监听提交
                layui.form.on('submit(demo1)', function (data2) {
                    var d = data2.field;
                    $.ajax({
                        type: "put",
                        url: "movieUpdate",
                        contentType: "application/json",
                        data: JSON.stringify(d),
                        success: function (data) {
                            if (data.msg == "修改成功") {
                                layer.msg(data.msg, {
                                    time: 1000
                                }, function () {
                                    layer.close(index1);
                                    my();
                                });

                            } else {
                                layer.msg(data.msg)
                            }
                        }
                    });

                    return false;
                });
            }
        });

        var $ = layui.$, active = {
            reload: function () {
                var demoReload = $('#demoReload');

                //执行重载
                table.reload('testReload', {
                    page: {
                        curr: 1
                        //重新从第 1 页开始
                    },
                    where: {
                        // 		          key: {
                        // 		            content: demoReload.val()
                        // 		          }
                        content: demoReload.val()
                    }
                });
            }
        };

        $('.demoTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>
</body>
</html>